package com.sign2024.sign2024project.goodsmaterials.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sign2024.sign2024core.common.param.PageParam;
import com.sign2024.sign2024core.entry.goodsmaterials.WzMajor;
import com.sign2024.sign2024project.goodsmaterials.mapper.WzMajorMapper;
import com.sign2024.sign2024project.goodsmaterials.service.WzMajorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yujie
 * @data 2024/8/27 16:25
 */
@Service
public class WzMajorServiceImpl implements WzMajorService {

    @Resource
    private WzMajorMapper wzMajorMapper;

    @Override
    public void insertBatchWzMajor(List<WzMajor> list) {
        wzMajorMapper.insertBatchWzMajor(list);
    }

    @Override
    public void cleanWzMajor() {
        wzMajorMapper.cleanWzMajor();
    }

    @Override
    public Page<WzMajor> pageWzMajor(PageParam param) {
        Integer offset = (param.getPageNum() - 1) * param.getPageSize();
        param.setOffset(offset);

        // 分页查询
        Page<WzMajor> page = new Page<>(param.getPageNum(), param.getPageSize());
        List<WzMajor> list = wzMajorMapper.selectWzMajorByPage(param);

        // 页码
        page.setCurrent(param.getPageNum());
        page.setSize(param.getPageSize());

        // 总记录数
        Long aLong = wzMajorMapper.pageWzMajorCount(param);
        page.setTotal(aLong);
        page.setRecords(list);

        return page;
    }
}
